package com.lxn.hrm.fallback;

import com.lxn.doc.CourseDoc;
import com.lxn.hrm.feignclients.ESFeignClient;
import com.lxn.hrm.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class ESFeignClientFallbackFactory implements FallbackFactory<ESFeignClient> {

    @Override
    public ESFeignClient create(final Throwable throwable) {
        throwable.printStackTrace();

        return new ESFeignClient(){

            @Override
            public AjaxResult save(CourseDoc courseDoc) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false)
                        .setMessage("ES服务不可用["+throwable.getMessage()+"]");
            }

            @Override
            public AjaxResult deleteById(Long id) {
                throwable.printStackTrace();
                return AjaxResult.me().setSuccess(false)
                        .setMessage("ES服务不可用["+throwable.getMessage()+"]");
            }
        };
    }
}
